﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.App_Start
{
    /// <summary>
    /// 模拟简单路由，路由是全局静态的，所以做成单例
    /// </summary>
    public class RoutingInfo
    {
        private static object _Lock = new object();
        private static IDictionary<string, Type> routInfo = null;
        static RoutingInfo()
        {
            routInfo = new Dictionary<string, Type>();
        }
        public void AddType(string name, Type type)
        {
            // 双 if + lock 防异步冲突
            if (!routInfo.ContainsKey(name))
            {
                lock (_Lock)
                {
                    if (!routInfo.ContainsKey(name))
                        routInfo.Add(name, type);
                }
            }
        }
        public Type GetType(string name)
        {
            if (routInfo.ContainsKey(name))
            {
                return routInfo[name];
            }
            return null;
        }
    }
}